package by.msokoloff.javaweb2015.webapp.page.plane;

import java.util.ArrayList;
import java.util.Arrays;

import javax.inject.Inject;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;

import by.msokoloff.javaweb2015.datamodel.Plane;
import by.msokoloff.javaweb2015.datamodel.PlaneModel;
import by.msokoloff.javaweb2015.datamodel.enums.PlaneStatus;
import by.msokoloff.javaweb2015.services.PlaneModelService;
import by.msokoloff.javaweb2015.services.PlaneService;
import by.msokoloff.javaweb2015.webapp.page.EntityListPage;

public class PlaneForm extends Form<Plane> {

	@Inject
	private PlaneService planeService;
	
	@Inject
	private PlaneModelService planeModelService;

	private Plane plane;

	public PlaneForm(String id, IModel<Plane> model) {
		super(id, model);
		add(new Label("id"));
		add(new DropDownChoice<PlaneModel>("planeModel", planeModelService.getAll()));
		add(new TextField<String>("boardNumber"));
		add(new DropDownChoice<PlaneStatus>("status", new ArrayList<PlaneStatus>(Arrays.asList(PlaneStatus.values()))));
				
		add(new FeedbackPanel("feedbackpanel"));
		plane = model.getObject();
	}

	@Override
	public final void onSubmit() {
		planeService.createOrUpdate(plane);
		setResponsePage(new EntityListPage(Plane.class));
	}

	@Override
	public final void onError() {
		System.out.println("Error!");
	}
}
